<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>套接字上下文选项列表</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="context.html">上下文（Context）选项和参数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="context.http.html">HTTP context 选项</a></div>
 <div class="up"><a href="context.html">上下文（Context）选项和参数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="context.socket" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">套接字上下文选项</h1>
  <p class="refpurpose"><span class="refname">套接字上下文选项</span> &mdash; <span class="dc-title">套接字上下文选项列表</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-context.socket-description">
  <h3 class="title">说明</h3>
  <p class="para">
   套接字上下文选项可用于所有工作在套接字上的封装协议，像
   <em>tcp</em>, <em>http</em> 和
   <em>ftp</em>.
  </p>
 </div>

 
 <div class="refsect1 options" id="refsect1-context.socket-options">
  <h3 class="title">可选项</h3>
  <p class="para">
   <dl>

    
     <dt id="context.socket.bindto"><em><code class="parameter">bindto</code></em></dt>

     <dd>

      <p class="para">
       用户PHP访问网络的指定的IP地址（IPv4或IPv6其中的一个）和/或 端口号，这个语法是
       <em>ip:port</em>.
       Setting the IP or the port to <em>0</em> will let the system
       choose the IP and/or port.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        As FTP creates two socket connections during normal operation,
        the port number cannot be specified using this option.
       </p>
      </p></blockquote>
     </dd>

    
    
     <dt id="context.socket.backlog"><em><code class="parameter">backlog</code></em></dt>

     <dd>

      <p class="para">
       Used to  limit  the  number  of  outstanding  connections  in  the
       socket&#039;s  listen  queue.
      </p>
      <blockquote class="note"><p><strong class="note">Note</strong>: 
       <p class="para">
        This is only applicable to <span class="function"><a href="function.stream-socket-server.html" class="function">stream_socket_server()</a></span>.
       </p>
      </p></blockquote>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 changelog" id="refsect1-context.socket-changelog">
  <h3 class="title">更新日志</h3>
  <p class="para">
   <table class="doctable informaltable">
    
     <thead>
      <tr>
       <th>版本</th>
       <th>说明</th>
      </tr>

     </thead>

     <tbody class="tbody">
      <tr>
       <td>5.1.0</td>
       <td>
        Added <em>bindto</em>.
       </td>
      </tr>

      <tr>
       <td>5.3.3</td>
       <td>
        Added <em>backlog</em>.
       </td>
      </tr>

     </tbody>
    
   </table>

  </p>
 </div>

 
 <div class="refsect1 examples" id="refsect1-context.socket-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="context.socket.example-bindto">
    <p><strong>Example #1 Basic <em><code class="parameter">bindto</code></em> usage example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;connect&nbsp;to&nbsp;the&nbsp;internet&nbsp;using&nbsp;the&nbsp;'192.168.0.100'&nbsp;IP<br /></span><span style="color: #0000BB">$opts&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'socket'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'bindto'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'192.168.0.100:0'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;),<br />);<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;connect&nbsp;to&nbsp;the&nbsp;internet&nbsp;using&nbsp;the&nbsp;'192.168.0.100'&nbsp;IP&nbsp;and&nbsp;port&nbsp;'7000'<br /></span><span style="color: #0000BB">$opts&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'socket'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'bindto'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'192.168.0.100:7000'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;),<br />);<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;connect&nbsp;to&nbsp;the&nbsp;internet&nbsp;using&nbsp;port&nbsp;'7000'<br /></span><span style="color: #0000BB">$opts&nbsp;</span><span style="color: #007700">=&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'socket'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;array(<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #DD0000">'bindto'&nbsp;</span><span style="color: #007700">=&gt;&nbsp;</span><span style="color: #DD0000">'0:7000'</span><span style="color: #007700">,<br />&nbsp;&nbsp;&nbsp;&nbsp;),<br />);<br /><br /><br /></span><span style="color: #FF8000">//&nbsp;create&nbsp;the&nbsp;context...<br /></span><span style="color: #0000BB">$context&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">stream_context_create</span><span style="color: #007700">(</span><span style="color: #0000BB">$opts</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;...and&nbsp;use&nbsp;it&nbsp;to&nbsp;fetch&nbsp;the&nbsp;data<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #0000BB">file_get_contents</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">false</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$context</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 
</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="context.html">上下文（Context）选项和参数</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="context.http.html">HTTP context 选项</a></div>
 <div class="up"><a href="context.html">上下文（Context）选项和参数</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
